package com.codeape.fast.data;

import android.util.Log;

import com.codeape.fast.data.model.LoggedInUser;

import java.io.IOException;

import timber.log.Timber;


/**
 * Class that handles authentication w/ login credentials and retrieves user information.
 */
public class LoginDataSource {
    private static final String TAG = "LoginDataSource";

    /**
     * 退出登录 logout  LoginDataSource
     * res/drawable/ides.png
     * com.codeape.fast.data.LoginDataSource#logout(java.lang.String)
     */
    public void logout() {
        // TODO: 关注 代码猿力，每天学习一点开发新技能，提高开发效率
    }

    public void logout(String reason) {
        // TODO: 关注 代码猿力，每天学习一点开发新技能，提高开发效率
    }

    public void logout(int flag) {
        // TODO: 关注 代码猿力，每天学习一点开发新技能，提高开发效率
    }

    public Result<LoggedInUser> login(String username, String password) {
        Timber.d("login() called with: username = [" + username + "], password = [" + password + "]");
        try {
            // TODO: handle loggedInUser authentication
            if (password.contains("123")) {
                LoggedInUser fakeUser =
                        new LoggedInUser(
                                java.util.UUID.randomUUID().toString(),
                                "Jane Doe");
                Timber.i("login: success , name " + username + " password " + password);
                return new Result.Success<>(fakeUser);
            } else {
                Timber.w("login: error, name " + username + " password " + password);
                return new Result.Error(new Exception("error"));
            }

        } catch (Exception e) {
            return new Result.Error(new IOException("Error logging in", e));
        }
    }


}